<template>
  <div class="bg-box">
    <Nav :isBlack="false"></Nav>
    <div class="main-box">
      <div class="left-box">
        <div class="left-menu">
          <div :class="{ active: menuIndex == 0 }" @click="changeRule(0)">按点赞排序</div>
          <el-divider direction="vertical"></el-divider>
          <div :class="{ active: menuIndex == 1 }" @click="changeRule(1)">按时间排序</div>
          <el-divider direction="vertical"></el-divider>
          <div :class="{ active: menuIndex == 2 }" @click="changeRule(2)">按热度排序</div>
        </div>
        <el-divider></el-divider>
        <div class="article">
          <div v-for="(item, i) in communityItem" :key="i">
            <div class="article-item" @click="to('/article', { articleId: item.articleId, uuid: userInfo.uuid })">
              <div class="article-left">
                <div class="article-item-row1" style=" margin-top:0;">
                  <div>{{ item.userName }}</div>
                  <el-divider direction="vertical"></el-divider>
                  <div>{{ item.uploadDate }}</div>
                </div>
                <div class="article-item-row2">
                  {{ item.title }}
                </div>
                <div class="article-item-row3">
                  {{ item.description }}
                </div>
                <div class="article-item-row4">
                  <div class="row4-item">
                    <img src="@/assets/visit.svg" />
                    <div>{{ item.browse }}</div>
                  </div>
                  <div class="row4-item">
                    <img src="@/assets/commit.svg" />
                    <div>{{ item.commit }}</div>
                  </div>
                  <div class="row4-item">
                    <img src="@/assets/like.svg" class="like"/>
                    <div>{{ item.like }}</div>
                  </div>
                </div>
              </div>
              <div class="article-right" v-if="item.coverUrl">
                <img :src="item.coverUrl" style='width: 100px;height: 100px;' />
              </div>
            </div>
            <el-divider></el-divider>
          </div>
        </div>
      </div>
      <div class="right-box"></div>
    </div>
  </div>

</template>

<script setup>
import { ref } from 'vue'
import Nav from '@/components/Nav.vue'
import { useRoute, useRouter } from 'vue-router'
import { getCommunity } from '@/api.js'
const router = useRouter();
const to = (url, query = {}) => {
  router.push({
    path: url,
    query
  })
}
const userInfo = JSON.parse(localStorage.getItem('userInfo'))
const menuIndex = ref(0)
const communityItem = ref([])
const changeRule = (index) => {
  menuIndex.value = index;
}
getCommunity(1, 10, 1).then(res => {

  console.log(res);
  communityItem.value = res.article
})
</script>

<style scoped>
.article {
  display: flex;
  flex-direction: column;
}

.article-item-row1 {
  display: flex;
  font-size: 14px;

}

.article-item-row2 {
  font-weight: bold;
}

.article-item-row3 {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.article-item-row4 {
  display: flex;

}

.article-item-row4 img {
  margin-right: 10px;
}

.article-item-row4 div {
  font-size: 14px;
}

.row4-item {
  margin-right: 60px;
  display: flex;
  align-items: center;
}


.article-item {
  width: 100%;
  display: flex;
  align-items: center;
  cursor: pointer;
}

.article-left>div {
  margin-top: 16px;
}

.article-left {
  width: 85%;
}

.bg-box {
  background-color: #eee;
  position: absolute;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
}

.main-box {
  margin-top: 20px;
  width: 1200px;
}

.left-box {
  background-color: #fff;
  width: 790px;
  padding: 10px 20px;
}

.left-menu {
  display: flex;
  align-items: center;
  font-size: 13px;
  margin-top: 10px;
  margin-left: 10px;
}

.active {
  color: #004DFF;
}
.like {
  font-size: 20px;
  margin-right: 4px;
  height: 1em;
  width: 1em;
  cursor: pointer;
}
</style>